<?php
    $this->headTitle('Phân quyền','append');
    $mResource = new Admin_Model_Resource;
    $adminResource = $mResource->getData(array('moduleName'=>'admin'));
    $defaultResource = $mResource->getData(array('moduleName'=>'default'));
    $adControl = array();
    $deControl = array();
    foreach($adminResource as $re){
    if(!in_array($re['controllerName'], $adControl))
        $adControl[] = $re['controllerName'];                                    
    }
    foreach($defaultResource as $re){
    if(!in_array($re['controllerName'], $deControl))
        $deControl[] = $re['controllerName'];                                    
    }
?>
<div class="row-fluid page-head">
    <h2 class="page-title"><i class="fontello-icon-monitor"></i> Phân quyền <small>Thêm mới</small></h2>
    <p class="pagedesc">Description</p>
    <div class="page-bar">
        <div class="btn-toolbar"> </div>
    </div>
</div>
<!-- // page head -->

<div class="row-fluid">
    <div id="page-content" class="page-content tab-content overflow-y">               
        <div class="row-fluid">
            <div class="span12 grider">
                <div class="widget widget-simple">
                    <div class="widget-content">                                                
                        <div class="widget-body">
                            <?php
                                if(isset($this->mess)){
                                    if($this->flag == 'success')
                                        echo '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button><span class="bold">'.$this->messTitle.'</span> '.$this->mess.'</div>';
                                    elseif($this->flag == 'info')
                                        echo '<div class="alert alert-info"><button type="button" class="close" data-dismiss="alert">×</button><span class="bold">'.$this->messTitle.'</span> '.$this->mess.'</div>';
                                    elseif($this->flag == 'warning')
                                        echo '<div class="alert alert-warning"><button type="button" class="close" data-dismiss="alert">×</button><span class="bold">'.$this->messTitle.'</span> '.$this->mess.'</div>';
                                    elseif($this->flag == 'danger')
                                        echo '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert">×</button><span class="bold">'.$this->messTitle.'</span> '.$this->mess.'</div>';
                                }                                
                            ?>   
                            <form id="" class="form-horizontal" method="post" action="" novalidate="novalidate" enctype="multipart/form-data">                                            
                                <div class="row-fluid">
                                    <div class="span12 form-dark">
                                        <fieldset>  
                                            <legend>Thông tin phân quyền <small></small></legend>
                                            <ul class="form-list label-left list-bordered dotted">
                                                <!-- // form item -->
                                                <li class="control-group">                                                                                                                                    
                                                    <label for="accountPrefix" class="control-label">Tên phân quyền *</label>
                                                    <div class="controls">                                                        
                                                        <input type="text" name="roleName" id="roleName" value="" class="span12" placeholder="Tên phân quyền"/>                                                                    
                                                    </div>
                                                </li>
                                            </ul>                                                      
                                            <ul class="form-list label-left list-bordered dotted">
                                                <li class="section-form">
                                                    <h4>Phân quyền chức năng Admin</h4>
                                                </li>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                            </ul>
                                            <table id="table-resource" class="table boo-table table-striped table-content table-hover dataTable" data="resourceAdminFunc">
                                                <thead>
                                                    <tr>                                
                                                        <th scope="col"><input type='checkbox' class='resourceIdAdmin' name='' value=''/><span class="column-sorter"></span></th>
                                                        <th scope="col">Name <span class="column-sorter"></span></th>                                            
                                                        <th scope="col">Controller <span class="column-sorter"></span></th>
                                                        <th scope="col">Action <span class="column-sorter"></span></th>                                                                                                                                                                                            
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php                            
                                                        foreach ($adControl as $resource){                                                                                                                        
                                                            $temp = $mResource->getData(array('moduleName'=>'admin','controllerName'=>$resource));                                                            
                                                            $i=0;
                                                            foreach($temp as $re){$i++;
                                                    ?>
                                                                <tr>   
                                                                    <td><input type='checkbox' class='resourceIdAdmin' name='resourceId[]' value='<?php echo $re['resourceId']?>'/></td>                                                                    
                                                                    <?php
                                                                    	if($i==1){
                                                                    	   echo '<td style="text-align:center;vertical-align:middle" rowspan="'.$temp->count().'">'.strtoupper($re['controllerName']).'</td>';
                                                                    	}
                                                                    ?>                                   
                                                                    <td><?php echo strtoupper($re['actionName']);?></td>
                                                                    <td><?php echo $re['resourceName'];?></td>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
                                                                </tr>                                                                                                                
                                                    <?php
                                                            }
                                                    	}
                                                    ?>
                                                </tbody>
                                            </table>
                                            <!-- // DATATABLE FUNC -->
                                            
                                            <ul class="form-list label-left list-bordered dotted">
                                                <li class="section-form">
                                                    <h4>Phân quyền chức năng Public</h4>
                                                </li>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                            </ul>                                                                                                                                                                                                                                
                                        </fieldset>
                                        <!-- // fieldset Input -->
                                        <div class="form-actions">                
                                            <input type="submit" name="submit" id="submit" value="Submit &amp; Validate" class="btn btn-blue"/>                
                                            <input type="reset" name="reset" id="reset" value="Reset" class="btn btn-yellow"/>                                            
                                        </div>                                                
                                    </div>                                    
                                    <div class="row-fluid">
                                        <div class="span12 form-dark">
                                            
                                        </div>
                                    </div>
                                </div>
                            </form>                         
                        </div>
                    </div>                
                </div>
            </div>
        </div>               
    </div>
</div>


               
                <form id="form" class="form-option" method="post" action="" enctype="multipart/form-data" name="form">
                    <dl class="zend_form">
                        <dt><label>Tên quyền</label></dt>
                        <dd><input type="text" id="roleName" name="roleName" value=""/></dd>                        
                        <dt><label>Chức năng admin</label></dt>
                        <dd>
                            <div class="option-wrapper">
                                <div class="fieldset">
                                    <div class="legend"><input type="checkbox" id="check_all_resource_admin"/><label>Chọn hết</label></div>
                                    <div class="fieldset-content">
                                    <ul>
                                    <?php 
                                        foreach ($this->resourceList as $resource){
                                            if($resource['moduleName'] == 'admin')
                                                echo "<li><input type='checkbox' class='resourceIdAdmin' name='resourceId[]' value='{$resource['resourceId']}'><label>{$resource['resourceName']}</label></li>";
                                        }
                                    ?>
                                    <div class="clearfix"></div>
                                    </ul>
                                    </div>
                                </div>
                            </div>
                        </dd>
                        <dt><label>Chức năng default</label></dt>
                        <dd>
                            <div class="option-wrapper">
                                <div class="fieldset">
                                    <div class="legend"><input type="checkbox" id="check_all_resource_default"/><label>Chọn hết</label></div>
                                    <div class="fieldset-content">
                                    <ul>
                                    <?php 
                                        foreach ($this->resourceList as $resource){
                                            if($resource['moduleName'] == 'default')
                                                echo "<li><input type='checkbox' class='resourceIdDefault' name='resourceId[]' value='{$resource['resourceId']}'><label>{$resource['resourceName']}</label></li>";
                                        }
                                    ?>
                                    <div class="clearfix"></div>
                                    </ul>
                                    </div>
                                </div>
                            </div>
                        </dd>
                        
                        <dd id="submit-element">
                            <input value="Thêm mới" class="button" type="submit" />
                            <input value="Reset" class="button" type="reset"/>
                        </dd>
                    </dl>
                </form>          